package mushystuff.dtb.web.vo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import mushystuff.dtb.core.model.Product;

public class ProductVO {
    
    private long id;
    
    private String name;
    
    private boolean active;
    
    private Date lastModified;
    
    private int numberOfStories;
    
    private int numberOfSprints;
    
    public ProductVO() {
        
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public Date getLastModified() {
        return lastModified;
    }

    public void setLastModified(Date lastModified) {
        this.lastModified = lastModified;
    }
    
    public int getNumberOfStories() {
        return numberOfStories;
    }

    public void setNumberOfStories(int numberOfStories) {
        this.numberOfStories = numberOfStories;
    }

    public int getNumberOfSprints() {
        return numberOfSprints;
    }

    public void setNumberOfSprints(int numberOfSprints) {
        this.numberOfSprints = numberOfSprints;
    }

    public static ProductVO[] convert(Collection<Product> products) {
        Collection<ProductVO> res = new ArrayList<ProductVO>();
        for (Product product : products) {
            ProductVO vo = new ProductVO();
            vo.setId(product.getId());
            vo.setName(product.getName());
            vo.setActive(product.isActive());
            vo.setLastModified(product.getLastModified());
            vo.setNumberOfSprints(product.getSprints().size());
            vo.setNumberOfStories(product.getBacklog().size());
            res.add(vo);
        }
        ProductVO[] resArray = new ProductVO[res.size()];
        resArray = res.toArray(resArray);
        return resArray;
    }

}
